package com.example.demo4;

import android.content.Context;
import android.os.HardwarePropertiesManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class List_view_Adapter extends BaseAdapter {
    private List<Mode_v> list;
    private Context context;    //上下文
    private int resource;    //模型资源
    public List_view_Adapter(Context context,int resource,List<Mode_v> list) {
        this.context=context;
        this.resource=resource;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Mode_v data = (Mode_v) getItem(i);
        View v;
        ViewHolder holder;
        if(view==null)
        {
            v= LayoutInflater.from(context).inflate(resource,viewGroup,false);
            holder=new ViewHolder();
            holder.img=v.findViewById(R.id.img);
            holder.title=v.findViewById(R.id.title);
            holder.nr=v.findViewById(R.id.content);
            holder.time=v.findViewById(R.id.time);
            v.setTag(holder);
        }else
        {
            v=view;
            holder= (ViewHolder) v.getTag();
        }
        holder.img.setBackgroundResource(data.getImg());
        holder.title.setText(data.getTitle());
        holder.nr.setText(data.getContent());
        holder.time.setText(data.getTime());
        return v;
    }
    class ViewHolder
    {
        ImageView img;
        TextView title;
        TextView nr;
        TextView time;
    }
}
